
from lib import *

def poll_compare():
	import time
	import re
	import os

	url			= 'http://web.oa.wanmei.com/newscenter/education/Pages/Forms/AllItems.aspx'
	pattern		= r'<li class="sb_li2"><a href=.+?target="_blank">(.+?)</a></li>'

	poll_time	= 120
	last_catalog= set()
	while True:
		try:
			page	= web(url)
			text	= page.text
		except Exception as ex:
			print(ex)	
			continue

		if not text: continue

		flog(text)
		break
		
		catalog	= set()
		for match in re.finditer(pattern, text, re.DOTALL):
			title	= match.group(1)
			if not title: continue

			title	= re.sub(r'[！，（） 　{更}第章节卷—零一二三四五六七八九十百千]', r'', title)
			catalog.add(title)
		
		if last_catalog and last_catalog!= catalog:
			diff= catalog - last_catalog
			if diff:
				print('Find update', diff, ' at: ', time.strftime('%Y-%m-%d %X', time.localtime()))
				os.startfile(url)
		flog(catalog)
		last_catalog	|= catalog
		time.sleep(poll_time)

if __name__=='__main__':
	poll_compare()
